﻿using DryIoc;
using Prism.Commands;
using Prism.Common;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WheelClean2.Model;
using WheelClean2.Mould;

namespace WheelClean.ViewModels
{
    class LaserListViewModel : BindableBase, INavigationAware
    {
        private readonly IRegionManager _regionManager;
        private readonly IDialogService _dialog;
        private ObservableCollection<LaserInfo> _deviceInfos;
        /// <summary>
        /// 设备列表
        /// </summary>
        public ObservableCollection<LaserInfo> DeviceInfos
        {
            get { return _deviceInfos; }
            set { SetProperty(ref _deviceInfos, value); }
        }

        public DelegateCommand<string> DelegateCommand_Open { get; private set; }

        LaserListViewModel(IRegionManager contentRegion, IDialogService dialog)
        {
            _regionManager = contentRegion;
            _dialog = dialog;
            DeviceInfos = new ObservableCollection<LaserInfo>();
            //获取所有设备
            using (var db = new AppDbContext())
            {
                DeviceInfos.AddRange(db.LaserInfos.ToList());
            }
            DelegateCommand_Open = new DelegateCommand<string>(Open);

        }
        private void Open(string obj)
        {
            if (!string.IsNullOrEmpty(obj)&&obj== "control")
            {
                DialogParameters parameters = new DialogParameters();
                parameters.Add("type", obj);
                // 导航到 ContentRegion 中指定的视图
                _dialog.ShowDialog("LaserControl", parameters, null);
            }

            // viewName 可能是 "HomeView", "SettingsView", "AboutView" 等
          else if (!string.IsNullOrEmpty(obj))
            {
                DialogParameters parameters = new DialogParameters();
                parameters.Add("type", obj);
                // 导航到 ContentRegion 中指定的视图
                _dialog.ShowDialog("LaserParameters", parameters, null);

            }
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
          
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
           
        }
    }
}
